/*
 * @Author: Starfish_DL
 * @Date: 2020-11-08 13:30:48
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-11-08 13:38:29
 * @CurrentVersion: 1.0
 * @Description: 
 */

public class TestSingleton {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s2 == s1);
    }
}

/**
 * Singleton
 */
class Singleton {

    private static Singleton instance = null;

    private Singleton() {
    }

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}